<?php

namespace app\model;

use think\facade\Db;
use think\Model;

class PostWhiteUserModel extends Model {

    protected $table ="post_white_user";

    protected $pk = 'id';

    /*
   * 获取total
   * */
    public function getTotal($where=[]){
        return Db::name($this->table)->where($where)->count();
    }


    /*
   * 获取list
   * */
    public function getList($where,$page = null,$limit = null,$orderFields){

        $obj =  Db::name($this->table)->where($where);

        if(!empty($field) ) {
            $obj = $obj->field($field);
        }

        if(!empty($page) && !empty($limit)){
            $obj = $obj->page($page, $limit);
        }

        if(!empty($orderFields)){
            $obj = $obj->order($orderFields);
        }

        $list = $obj->select();

        if($list){
            return $list;
        }
        return [];
    }


   public function isWhiteUser($uid){
        return $this->getTotal(["uid"=>$uid,"accept_status"=>1]) > 0 ;
   }



    public function addOne($data){
        return Db::name($this->table)->insertGetId($data);
    }

    /*
    * 修改运单号
    * */
    public function updateOne($id, $data){
        $where[] = [$this->pk,"=",$id];
        return Db::name($this->table)->where($where)->update($data);
    }


}